<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet" href="./AmazeUI-2.4.2/assets/css/amazeui.css"/>
    <link href="./css/dlstyle.css" rel="stylesheet" type="text/css">
    <script src="./AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="./AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>

    <!-- 导入vue和axios的js文件 -->
    <script src="./plugins/vue/dist/vue.js"></script>
    <script src="./plugins/axios/dist/axios.js"></script>
    <script src="./js/common.js"></script>
    <style type="text/css">
        .validateMsg {color: red;font-size: 12px;}
    </style>
</head>

<body>
<div id="app">
    <div class="login-boxtitle">
        <a href="home.html"><img alt="logo" src="./images/logobig.png"/></a>
    </div>

    <div class="login-banner">
        <div class="login-main">
            <div class="login-banner-bg"><span></span><img src="./images/big.jpg"/></div>
            <div class="login-box">
                <!--选项卡-->
                <div class="am-tabs" id="doc-my-tabs">
                    <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                        <li class="am-active"><a href="">账号登录</a></li>
                        <li><a href="">手机验证码登录</a></li>
                    </ul>
                    <div class="am-tabs-bd">
                        <!-- 账号登录 -->
                        <div class="am-tab-panel am-active">
                            <form :model="userForm">
                                <div class="user-name">
                                    <label for="user"><i class="am-icon-user"></i></label>
                                    <input type="text" v-model="userForm.username" id="user" placeholder="邮箱/手机/用户名">
                                </div>
                                <div class="user-pass">
                                    <label for="password"><i class="am-icon-lock"></i></label>
                                    <input type="password" v-model="userForm.password" id="password" placeholder="请输入密码">
                                </div>
                            </form>
                            <div class="login-links">
                                <label for="remember-me"><input id="remember-me" :checked="userForm.rememberMe" @click="userForm.rememberMe = !userForm.rememberMe" type="checkbox">记住密码</label>
                                <a href="#" class="am-fr">忘记密码</a>
                                <a href="register.html" class="am-fr">注册&nbsp;&nbsp;</a>
                                <br/>
                            </div>
                            <div class="am-cf">
                                <input type="button" @click="userLogin" value="登 录" class="am-btn am-btn-primary am-btn-sm">
                            </div>
                        </div>
                        <!-- 手机验证码登录 -->
                        <div class="am-tab-panel">
                            <form method="post" :model="loginForm" >
                                <div class="user-phone">
                                    <div>
                                        <label for="phone"><i class="am-icon-mobile-phone am-icon-md"></i></label>
                                        <input type="tel" name="" v-model="loginForm.phone" @blur="validPhone" id="phone" placeholder="请输入手机号">
                                    </div>
                                    <span class="validateMsg">{{phoneValidateMsg}}</span>
                                </div>
                                <div class="verification">
                                    <label for="code"><i class="am-icon-code-fork"></i></label>
                                    <input type="tel" name="" v-model="loginForm.verifyCode" id="code" placeholder="请输入验证码">
                                    <button type="button" class="btn" :disabled="btnDisabled" @click="sendMobileCode" id="dyMobileButton" style="margin-bottom: 15px;">
                                        {{btnText}}
                                    </button>
                                </div>
                            </form>
                            <div class="login-links">
                                <a href="register.html" class="am-fr">注册</a>
                                <br/>
                            </div>
                            <div class="am-cf">
                                <input type="button" name="" value="登 录" @click="phoneLogin" class="am-btn am-btn-primary am-btn-sm">
                            </div>
                        </div>
                    </div>
                    <div class="partner">
                        <h3>合作账号</h3>
                        <div class="am-btn-group">
                            <li><a href="#"><i class="am-icon-qq am-icon-sm"></i><span>QQ登录</span></a></li>
                            <li><a href="#"><i class="am-icon-weibo am-icon-sm"></i><span>微博登录</span> </a></li>
                            <li><a href="javascript:void(0);" @click="wechatLogin"><i class="am-icon-weixin am-icon-sm"></i><span>微信登录</span> </a></li>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <div class="footer ">
        <div class="footer-hd ">
            <p>
                <a href="# ">恒望科技</a>
                <b>|</b>
                <a href="# ">商城首页</a>
                <b>|</b>
                <a href="# ">支付宝</a>
                <b>|</b>
                <a href="# ">物流</a>
            </p>
        </div>
        <div class="footer-bd ">
            <p>
                <a href="# ">关于恒望</a>
                <a href="# ">合作伙伴</a>
                <a href="# ">联系我们</a>
                <a href="# ">网站地图</a>
                <em>© 2015-2025 Hengwang.com 版权所有. 更多模板 <a href="http://www.cssmoban.com/" target="_blank"
                                                           title="模板之家">模板之家</a> - Collect from <a
                        href="http://www.cssmoban.com/" title="网页模板" target="_blank">网页模板</a></em>
            </p>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        //开启选项卡功能
        $('#doc-my-tabs').tabs();
    });

    new Vue({
        el:"#app",
        data:{
            userForm:{
                username:'',
                password:'',
                rememberMe: false,
                type:'front'        //front表示前台用户登录，admin表示后台用户登录
            },
            loginForm:{
                phone:'',
                verifyCode:'',
                type:'phone_login'
            },
            phoneValidateMsg:'' ,    //手机号验证消息
            PhoneValidateResult:false,
            btnText:'获取',          //按钮上面的文字
            btnDisabled:false,       //按钮是否禁用
            appid: 'wxd853562a0548a7d0',        //APPID
            callback: 'bugtracker.itsource.cn', //回调域名
            wechatUrl: 'https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect'
        },
        methods:{
            //验证手机号
            validPhone(){
                if(!/^1[3-9][0-9]{9}$/.test(this.loginForm.phone)){
                    this.phoneValidateMsg = '请输入正确的手机号！';
                    $('#phone').css("border","1px solid red");
                    return false;
                }
                //发送请求去查询数据库，验证手机号注册过
                this.$http.get("/lr/validatePhone/phone_login/"+this.loginForm.phone)
                    .then(res => {
                        let {success,message} = res.data;
                        if (success){
                            this.phoneValidateMsg = '';
                            $('#phone').css("border","1px solid green");
                            this.PhoneValidateResult =true;
                        }else {
                            this.phoneValidateMsg = message;
                            $('#phone').css("border","1px solid red");
                            this.PhoneValidateResult =false;
                        }
                    });
                return this.PhoneValidateResult;
            },
            //获取手机验证码
            sendMobileCode(){
                if(this.validPhone()){
                    this.btnDisabled =true;
                    let time =60;
                    this.btnText = time;
                    //开始倒计时：每个一分钟执行一次定时器
                    let intervalId = setInterval(()=>{
                        time--;
                        this.btnText = time;
                        if (time<=0){
                            clearInterval(intervalId);
                            this.btnDisabled = false;
                            this.btnText = '获取';
                        }
                    },1000);
                    this.$http.get("/lr/sendMobileCode/"+this.loginForm.type+"/"+this.loginForm.phone)
                        .then(res=>{
                            let {success,message} = res.data;
                            alert(message)
                        })
                }
                this.phoneValidateMsg = '请输入正确的手机号！';
                $('#phone').css("border","1px solid red");
            },
            //用户名密码登录
            userLogin(){
                this.$http.post('/lr/userLogin', this.userForm).then(res => {
                    let {success,message,data} = res.data
                    console.debug(success)
                    if(success){
                        localStorage.setItem("userToken",data.userToken);
                        localStorage.setItem("userJsonStr",data.userJsonStr);
                        location.href = '/index.html'
                    }else{
                        alert(message)
                    }
                })
            },
            //手机号登录
            phoneLogin(){
                this.$http.post('/lr/userLogin', this.loginForm).then(res => {
                    let {success,message,data} = res.data
                    if(success){
                        localStorage.setItem("userToken",data.userToken);
                        localStorage.setItem("userJsonStr",data.userJsonStr);
                        location.href = '/index.html'
                    }else{
                        alert(message)
                    }
                })
            },
            //微信登录
            wechatLogin(){
                let wechatUrl = this.wechatUrl
                    .replace("APPID", this.appid)
                    .replace("REDIRECT_URI", "http://" + this.callback + "/wechatLoginResult.html");
                location.href = wechatUrl
            }
        }
    })
</script>
</body>

</html>